
//
//  registerView.m
//  zhangGuangTianXia
//
//  Created by tangtangchitangtang on 2017/11/7.
//  Copyright © 2017年 tangtangchitangtang. All rights reserved.
//

#import "registerView.h"
#import "determineViewController.h"
@implementation registerView
-(void)creatView{

    UIImageView *imageView=[UIImageView new];
    [self addSubview:imageView];
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.bottom.mas_equalTo(0);
    }];
    
    
    UIView *textView=[UIView new];
    [self addSubview:textView];
    [textView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.right.mas_equalTo(-20);
        make.height.mas_equalTo(50);
        make.top.mas_equalTo(130);
    }];
    textView.backgroundColor=ColorWithRGB(240, 240, 240);
    textView.layer.cornerRadius=25;
    
    
    _phoneText=[UITextField new];
    [textView addSubview:_phoneText];
    [_phoneText mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(30);
        make.right.mas_equalTo(-30);
        make.height.mas_equalTo(50);
        make.centerY.mas_equalTo(0);
    }];
    _phoneText.placeholder=@"手机号码";
    _phoneText.textColor=ColorWithRGB(49, 49, 49);
    _phoneText.font=[UIFont systemFontOfSize:17];
    _phoneText.returnKeyType=UIReturnKeyDone;
    _phoneText.keyboardType=UIKeyboardTypePhonePad;
    
    UIView *textView2=[UIView new];
    [self addSubview:textView2];
    [textView2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.right.mas_equalTo(-20);
        make.height.mas_equalTo(50);
        make.top.mas_equalTo(textView.mas_bottom).mas_equalTo(20);
    }];
    textView2.backgroundColor=ColorWithRGB(240, 240, 240);
    textView2.layer.cornerRadius=25;
    
    
    _codeText=[UITextField new];
    [textView2 addSubview:_codeText];
    [_codeText mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(30);
        make.right.mas_equalTo(-30);
        make.height.mas_equalTo(50);
        make.centerY.mas_equalTo(0);
    }];
    _codeText.placeholder=@"设置密码";
    _codeText.textColor=ColorWithRGB(49, 49, 49);
    _codeText.font=[UIFont systemFontOfSize:17];
    _codeText.keyboardType=UIKeyboardTypeNamePhonePad;
    _codeText.delegate=self;
    _codeText.secureTextEntry=YES;//密文
    _codeText.returnKeyType=UIReturnKeyDone;
    
    
    UIView *textView3=[UIView new];
    [self addSubview:textView3];
    [textView3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.right.mas_equalTo(-20);
        make.height.mas_equalTo(50);
        make.top.mas_equalTo(textView2.mas_bottom).mas_equalTo(20);
    }];
    textView3.backgroundColor=ColorWithRGB(240, 240, 240);
    textView3.layer.cornerRadius=25;
    
    _passwordText=[UITextField new];
    [textView3 addSubview:_passwordText];
    [_passwordText mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(30);
        make.right.mas_equalTo(-30);
        make.height.mas_equalTo(50);
        make.centerY.mas_equalTo(0);
    }];
    _passwordText.placeholder=@"确认密码";
    _passwordText.textColor=ColorWithRGB(49, 49, 49);
    _passwordText.font=[UIFont systemFontOfSize:17];
    _passwordText.keyboardType=UIKeyboardTypeNamePhonePad;
    _passwordText.delegate=self;
    _passwordText.secureTextEntry=YES;//密文
    _passwordText.returnKeyType=UIReturnKeyDone;
    
    
    UIView *textView4=[UIView new];
    [self addSubview:textView4];
    [textView4 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.right.mas_equalTo(-20);
        make.height.mas_equalTo(50);
        make.top.mas_equalTo(textView3.mas_bottom).mas_equalTo(20);
    }];
    textView4.backgroundColor=ColorWithRGB(240, 240, 240);
    textView4.layer.cornerRadius=25;
    
    
    _userNameText=[UITextField new];
    [textView4 addSubview:_userNameText];
    [_userNameText mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(30);
        make.right.mas_equalTo(-30);
        make.height.mas_equalTo(50);
        make.centerY.mas_equalTo(0);
    }];
    _userNameText.placeholder=@"昵称";
    _userNameText.textColor=ColorWithRGB(49, 49, 49);
    _userNameText.font=[UIFont systemFontOfSize:17];
    _userNameText.returnKeyType=UIReturnKeyDone;
    [_userNameText addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
    _userNameText.delegate=self;
    
    UIButton *btn=[UIButton new];
    [self addSubview:btn];
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(textView4);
        make.top.mas_equalTo(textView4.mas_bottom).mas_equalTo(40);
        make.height.mas_equalTo(50);
    }];
    btn.backgroundColor=_tianLanColor;
    [btn setTitleColor:[UIColor whiteColor] forState:0];
    [btn setTitle:@"下一步" forState:0];
    btn.titleLabel.font=[UIFont systemFontOfSize:17];
    btn.layer.cornerRadius=25;
    [btn addTarget:self action:@selector(registerBtn:) forControlEvents:UIControlEventTouchUpInside];


}

-(IBAction)registerBtn:(id)sender{
    NSString *phoneStr=_phoneText.text;
    if (![ZQTools isMobileNumber:phoneStr]) {
        [ZQTools svpInfo:@"手机号有误"];
        return;
    }
    NSString *passwordStr=_codeText.text;
    if ([ZQTools charIsNil:passwordStr]||passwordStr.length<6||passwordStr.length>17) {
        [ZQTools svpInfo:@"密码必须是6到17位字符组成"];
        return;
    }
    
    NSString *codeStr=_passwordText.text;
    if (![codeStr isEqualToString:passwordStr]) {
        [ZQTools svpInfo:@"两次密码不一致"];
        return;
    }

    NSString *nameStr=_userNameText.text;
    if ([ZQTools charIsNil:nameStr]) {
        [ZQTools svpInfo:@"昵称不能为空"];
        return;
    }
    determineViewController *determine=[[determineViewController alloc] init];
    determine.phoneStr=phoneStr;
    determine.passwordStr=passwordStr;
    determine.userNameStr=nameStr;
    [ZQTools pushNextViewController:self.viewController andRootController:determine];

}


- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString*)string{
    if ([[[UITextInputMode currentInputMode]primaryLanguage] isEqualToString:@"emoji"]) {
        return NO;
    }
    return YES;
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    return YES;
}

- (void)textFieldDidChange:(UITextField *)textField{
    if (textField.text.length>9) {
        [textField resignFirstResponder];
        _userNameText.text=[textField.text substringToIndex:10];
    }
}



@end
